package com.ui.home.view;

import android.content.Intent;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.LinearLayout;

import com.base.BaseFragment;
import com.ddd.wandemo.R;
import com.ui.home.adapter.HomeFragmentTabAdapter;
import com.widget.ShortIndicatorTabLayout;

import java.util.ArrayList;
import java.util.List;

public class HomeFragment extends BaseFragment {

    private String[] tabs = {"最新博文", "公众号", "项目"};
    private ViewPager mVpHomeFrag;
    private ShortIndicatorTabLayout mTlHomeFrag;
    private List<Fragment> mFragments = new ArrayList<>();
    private LinearLayout mLlSearch;


    public static HomeFragment newInstance() {
        HomeFragment fragment = new HomeFragment();
        return fragment;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_test2;
    }

    @Override
    protected void initView() {
        mVpHomeFrag = mView.findViewById(R.id.vp_home_frag);
        mTlHomeFrag = mView.findViewById(R.id.tl_home_frag);
        mLlSearch = mView.findViewById(R.id.ll_search_bar);

    }

    @Override
    protected void initEventAndData() {
        mFragments.add(HomeArticleFragment.newInstance());
        mFragments.add(new HomeWxArticleFragment());
        mFragments.add(new HomeProjectFragment());

        HomeFragmentTabAdapter tabAdapter = new HomeFragmentTabAdapter(getChildFragmentManager(), mFragments, tabs);
        mVpHomeFrag.setAdapter(tabAdapter);
        mVpHomeFrag.setOffscreenPageLimit(mFragments.size());

        mTlHomeFrag.setupWithViewPager(mVpHomeFrag);

        mLlSearch.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext,SearchActivity.class);
                startActivity(intent);
                getActivity().overridePendingTransition(0,0);
            }
        });
    }


    @Override
    protected void loadData() {

    }
}
